package com.yang.myoschina.activity;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;

import com.yang.myoschina.R;
import com.yang.myoschina.adapter.MyViewPagerAdapter;

public class TestUIActivity extends AppCompatActivity {
    private Toolbar toolbar;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private NavigationView navigationView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_ui);

        toolbar = (Toolbar)findViewById(R.id.toolbar);
        toolbar.setTitle("ToolBar");
        setSupportActionBar(toolbar);

        tabLayout = (TabLayout)findViewById(R.id.tabId);
        tabLayout.addTab(tabLayout.newTab().setText("新闻"),true);
        tabLayout.addTab(tabLayout.newTab().setText("图片"),false);
        tabLayout.addTab(tabLayout.newTab().setText("文字"),false);
        tabLayout.addTab(tabLayout.newTab().setText("其他"),false);

        viewPager = (ViewPager)findViewById(R.id.viewPager);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        navigationView = (NavigationView)findViewById(R.id.navigationView);
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int itemId = item.getItemId();
                item.setChecked(true);
                return true;
            }
        });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        Log.d("MyTag","menuId:"+id);
        return super.onOptionsItemSelected(item);
    }
}
